package com.niuniu.rushdorm.mapper;
/**
 * @author rambo
 * 2022/11/25
 */
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.niuniu.rushdorm.pojo.entity.Bed;
import com.niuniu.rushdorm.pojo.response.EmptyCount;
import com.niuniu.rushdorm.pojo.response.Member;
import com.niuniu.rushdorm.pojo.response.MyRoom;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BedMapper extends BaseMapper<Bed> {
    @Select("SELECT rooms.id roomId,rooms.name roomName from beds  left join rooms on beds.room_id = rooms.id where uid = #{uid} ;")
    MyRoom GetRoom(long uid);
    @Select("SELECT users.name `name` from beds left join users on users.uid = beds.uid where room_id = #{roomId} and users.name is not null;")
    List<Member> GetMembers(long roomId);
    @Select("select buildings.id building_id,rooms.gender,COUNT(buildings.id) cnt from beds left join rooms on rooms.id = room_id left join buildings on buildings.id = rooms.building_id group by buildings.id,gender;")
    @Results(id = "getEmpty",value={
            @Result(property = "building_id",column = "building_id"),
    })
    List<EmptyCount> GetEmptyCount();

}
